<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript" src="<c:url value="/js/plug/area/load_area.js" />"></script>
<style>
.detailTable input[type="text"]{
	width: 210px;
}
</style>
<div class="easyui-layout" style="width:100%;height:100%;" fit="true">
    <div data-options="region:'center',title:'',split:true" style="height:100%;">
		<form id="buyerInfoForm" method="post" >
		    <input type="hidden" id="buyerId" name="buyerId" data-options="required:true">
			<table class="detailTable"> 
    	 	<tr>
                <th>采购商名称:</th> 
                <td><input class="easyui-validatebox " id="chsName" name="chsName" data-options="required:true,validType:'chinese'"></td>
                <th>采购商编号:</th>
                <td><input class="easyui-validatebox" id="buyerCode" name="buyerCode" data-options="required:true">
                </td>
            </tr>
            <tr>
                <th>英文名:</th>
                <td><input class="easyui-validatebox " id="engName" name="engName" data-options="validType:'english'"></td>
                <th>拼音:</th><td><input class="easyui-validatebox" id="spell"name="spell" data-options="validType:'english'"></td>
            </tr>
             <tr>
                <th>地区:</th>
                <td>
                 <div id="loc" >
                   <select name="province" id="province" style="width:100px;">
                     <option value="0">选择省</option>
                   </select>   
                   <select name="city" id="city" style="width:100px;">
                     <option value="0">选择市</option>
                   </select>   
                   <select name="district" id="district" style="width:100px;">
                     <option value="0">选择地区</option>
                   </select>
                  </div>
                  <input type="hidden" id="areaCode" name="areaCode" data-options="required:true" >
                  <input type="hidden" id="areaName" name="areaName" data-options="required:true" >
                <th>邮编:</th>
                <td><input class="easyui-validatebox" id="zip" name="zip" data-options="validType:'zip'"></td>
            </tr>
            <tr>
                <th>采购商地址:</th>
                <td colspan="3" ><input class="easyui-validatebox" id="address" name="address"  style="width:400px;" ></td>
            </tr>
            <tr>
                <th>电话:</th>
                <td><input class="easyui-validatebox " id="phone" name="phone" data-options="validType:'phone'"></td>
                <th>销售员:</th>
                <td><input class="easyui-validatebox " id="salesman" name="salesman" "></td>
            </tr>
            <tr>
                <th>法人:</th>
                <td><input class="easyui-validatebox " id="licenseLeader" name="licenseLeader"></td>
                
                <th>负责人:</th>
                <td><input class="easyui-validatebox " id="qualityMan" name="qualityMan"></td>
            </tr>
            <tr>
                <th>注册证号:</th>
                <td><input class="easyui-validatebox " id="orgNumber" name="orgNumber"></td>
                <th>许可证号:</th>
                <td><input class="easyui-validatebox " id="licenseNumber" name="licenseNumber"></td>
            </tr>
            <tr>
                <th>积分数量:</th>
                <td><input class="easyui-validatebox " id="integralAmount" name="integralAmount" data-options="validType:'integer'"></td>
                <th>生产经营范围:</th>
                <td><input class="easyui-validatebox " id="productionScope" name="productionScope"></td>
            </tr>
            <tr>
                <th>信用额度:</th>
                <td><input class="easyui-validatebox " id="creditamount" name="creditamount" data-options="validType:'integer'"></td>
                <th>信用天数:</th>
                <td><input class="easyui-validatebox " id="creditdays" name="creditdays" data-options="validType:'integer'"></td>
            </tr>
            <tr>
                <th>开票开户行名称:</th>
                <td><input class="easyui-validatebox " id="invbankname" name="invbankname"></td>
                <th>开票开户账号:</th>
                <td><input class="easyui-validatebox " id="invaccno" name="invaccno"></td>
            </tr>
            <tr>
                <th>开票税号:</th>
                <td><input class="easyui-validatebox " id="invtaxno" name="invtaxno"></td>
                <th>开票单位名称:</th>
                <td><input class="easyui-validatebox " id="invcustomname" name="invcustomname"></td>
            </tr>
             <tr>
                <th>开票地址:</th>
                <td colspan="3" ><input class="easyui-validatebox " id="invaddress" name="invaddress" style="width:400px;"></td>
            </tr>
            <tr>
                <th>营业执照地址:</th>
                <td><input class="easyui-validatebox " id="orgDept" name="orgDept"></td>
                <th>药品经营证发证单位:</th>
                <td><input class="easyui-validatebox " id="licenseDept" name="licenseDept"></td>
            </tr>
            <tr>
                <th>GSP证书号:</th>
                <td><input class="easyui-validatebox " id="gspNumber" name="gspNumber"></td>
                <th>GSP证书发证单位:</th>
                <td><input class="easyui-validatebox " id="gspDept" name="gspDept"></td>
            </tr>
            <tr>
               <th>是否连锁门店:</th>
                <td>
                    <input type="radio" id="isBranch" name="isBranch" value="0" checked="checked">不是
					<input type="radio" id="isBranch" name="isBranch" value="1" >是
               </td>
                <th>客户类型:</th>
                <td>
                    <input type="radio" name="buyerCategory" value="0" checked="checked"/>终端
                    <input type="radio" name="buyerCategory" value="1" />连锁
                    <input type="radio" name="buyerCategory" value="2" />调拨
                </td>
             </tr>
            <tr>
               <th>是否有效:</th>
                <td>
                    <input type="radio" id="approveStatus" name="approveStatus" value="0" checked="checked">无效
					<input type="radio" id="approveStatus" name="approveStatus" value="10" >有效
               </td>
               <th>是否审核:</th>
                <td>
                    <input type="radio" id="isValid" name="isValid" value="0" checked="checked">未审
					<input type="radio" id="isValid" name="isValid" value="1" >审核
               </td>
             </tr>
            <tr>
                <th>未通过审核原因:</th>
                <td colspan="3" ><input class="easyui-validatebox " id="examReson" name="examReson" style="width:400px;"></td>
            </tr>
            <tr>
                <th>采购限制:</th>
                <td colspan="3" ><input class="easyui-validatebox " id="buyProperty" name="buyProperty" style="width:400px;"></td>
            </tr>
            <tr>
                <th>注册地址:</th>
                <td colspan="3" ><input class="easyui-validatebox " id="registerAddress" name="registerAddress" style="width:400px;"></td>
            </tr>
            <tr>
                <th>工厂地址:</th>
                <td colspan="3" ><input class="easyui-validatebox " id="factoryAddress" name="factoryAddress" style="width:400px;"></td>
            </tr>
            <tr>
                <th>备注:</th>
                <td colspan="3" >
                   <textarea id="note" name="note" rows="2" cols="60"></textarea>
                </td>
            </tr>
	        <%
	        String onViewFlag = request.getParameter("onViewFlag");
	        onViewFlag=onViewFlag==null?"":onViewFlag;
	        if(onViewFlag.equals("")){
	        %>
             <tr>
			    <th>操作：</th>
				<td align="center" colspan="3" > 
					<input type="button" onclick="submitForm()" class="button" value="提交" >
					<input type="button" onclick="pms.resetForm('buyerInfoForm')" class="button" value="重置" >
				    <!-- <input type="button" onclick="test()" class="button" value="测试" >   -->      
				</td>
			</tr>
            <%} %>
		</table>
		</form>
    </div>
</div>  
<script>

var flag =0; // 标示 0：save方法，1：update方法
$(function(){
	var buyerId="<%=request.getParameter("code")%>";
	if(buyerId=="null"){	//save
		$("#loc").LocationSelect({
			data:"<c:url value='/js/plug/area/areas.json' />",
			areaCode:"341024"
		});
	}else{					//update
		flag = 1;
		var param = {"buyerId":buyerId};
 		$.pmsAjax({
			url:'<c:url value="/buyer/showEmCBuyerDetail.do"/>',
			data:param,
			success:function(data){
				var emCBuyer = data.data.emCBuyer;
				//console.log(emCBuyer);
				if(data.code=="200"){
					//alertShow("成功");
					$('#buyerInfoForm').form('load', emCBuyer);
					//doemCBuyerDetail(emCBuyer);
					$("input[name='buyerCode']").attr("readonly","readonly");
					$("#loc").LocationSelect({
						data:"<c:url value='/js/plug/area/areas.json' />",
						areaCode:emCBuyer.areaCode
					});
				}else{
					alertError(data.result);
				}
			}
		});
	}
})
function submitForm(){
	if(flag == 0){
		doInsert();
	}else{
		doUpdate();
	}	
}
//insert
function doInsert(){
	$('#buyerInfoForm').form('submit', {
	    url:"/admin/buyer/insertBuyer.do",  
	    onSubmit: function(param){
	    	if(!$("#buyerInfoForm").form('validate')){
	    		return false;
	    	}
	    	var area = $("#loc").getLocation('all').code;
	    	var name = $("#loc").getLocation('all').name;
	    	var province = $("#loc").getLocation('one').province;
	    	var city = $("#loc").getLocation('one').city;
	    	$("#areaCode").val(area);
	    	$("#areaName").val(name);
	    	$("#province").val(province);
	    	$("#city").val(city);
	    	//alert(area);
	    	//console.log(area);
	    	//时间对比
	    }, 
	    success:function(data){
		    var ret = eval("("+data+")");
	     	if(ret.code=='200'){
	     		parent.alertShow("新增成功");
	     		parent.buyersTable.refresh();
	     		parent.$("#w_buyer_detail").dialog('close');
		    }else{
		    	parent.alertError(ret.result);
			}
	    }
	});
}
//update
function doUpdate(){
	$('#buyerInfoForm').form('submit', {
	    url:'<c:url value="/buyer/updateBuyer.do"/>',
	    onSubmit: function(param){
	    	if(!$("#buyerInfoForm").form('validate')){
	    		return false;
	    	}
	    	var area = $("#loc").getLocation('all').code;
	    	var name = $("#loc").getLocation('all').name;
	    	$("#areaCode").val(area);
	    	$("#areaName").val(name);
	    	//console.log(name);
	    	//时间对比
	    }, 
	    success:function(data){
		    var ret = eval("("+data+")");
	     	if(ret.code=='200'){
	     		parent.alertShow("修改成功");
	     		parent.buyersTable.refresh();
	     		parent.$("#w_buyer_detail").dialog('close');
	     		
		    }else{
		    	alertError(ret.result);
			}
	    }
	});
}
function test(){
	$("#buyerCode").val("1");
	$("#chsName").val("测试采购商");
	$("#engName").val("engName");
	$("#spell").val("spell");
	$("#salesman").val("salesman");
	$("#address").val("天马路354号");
	$("#zip").val("324200");
	$("#phone").val("0570-88661035");
	$("#buyProperty").val("医药产品。。");
	$("#note").val("新注册的采购商。。。");
	$("#licenseLeader").val("licenseLeader");
	$("#registerAddress").val("湖墅南路123号");
	$("#leaderName").val("leaderName");
	$("#factoryAddress").val("环城北路1号");
	$("#orgNumber").val("orgNumber");
	$("#factoryAddress").val("factoryAddress");
	$("#productionScope").val("testScope");
	$("#licenseNumber").val("22222222");
	$("#creditamount").val(88888);
	$("#creditdays").val(20);
	$("#invbankname").val("中国银行");
	
	
	$("#invaccno").val("63492222");
	$("#invtaxno").val("333333333");
	$("#invaddress").val("城东支行");
	$("#invcustomname").val("浙江珍诚医药在线");
	$("#orgDept").val("开发部");
	
	$("#licenseDept").val("6349");
	$("#gspNumber").val("333333333");
	$("#gspDept").val("新塘路");
	$("#qualityMan").val("珍诚医药");
	$("#licenseAddress").val("新塘路78号");
	$("#examReson").val("I don't know!");
	
	$("#qualityMan").val("qualityMan");
	$("#integralAmount").val("502");
	$("#salesman").val("salesman");
	}
</script>
